// app.js
App({
    jumpPage(tag){
        console.log(tag)
        wx.navigateTo({
          url: `/pages/${tag}/${tag}`,
        })
        console.log(`/pages/${tag}/${tag}`)
    },
    switchTab(tag){
        console.log(tag)
        wx.switchTab({
          url: `/pages/${tag}/${tag}`,
        })
        console.log(`/pages/${tag}/${tag}`)
    },
    loadPageByGetRequest(url, onSet) {
        wx.showLoading({
            mask: true
        })
        wx.request({
            url: url,
            method: 'GET',
            success: (res) => {
                if (res.data.code == 100) {
                    onSet(res)
                } else {
                    wx.showToast({
                        title: '网络加载失败',
                    })
                }
            },
            complete: () => {
                wx.hideLoading()
            },
        })
    },
    deleteItem(url, onSuccess) {
        wx.showModal({
            title: '确认是否删除?',
            complete: (res) => {
                if (res.cancel) {
                    return
                }
                if (res.confirm) {
                    wx.showLoading({
                        title: '删除中',
                        mask: true
                    })
                    wx.request({
                        url: url,
                        method: 'DELETE',
                        success: (res) => {
                            onSuccess(res)
                        },
                        failed: (error)=>{
                            console.log(error)
                        },
                        complete: () => {
                            wx.hideLoading()
                        }
                    })
                }
            }
        })
    }
})